package com.chen.demo.config;

import java.beans.PropertyVetoException;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.mchange.v2.c3p0.ComboPooledDataSource;

@Configuration
@MapperScan("com.chen.demo.dao")
public class DateSourceConfiguration {
	@Value("${spring.datasource.driver-class-name}")
	private String jdbcDriver;
	@Value("${spring.datasource.url}")
	private String jdbcUrl;
	@Value("${spring.datasource.username}")
	private String jdbcUserName;
	@Value("${spring.datasource.password}")
	private String jdbcPassWord;

	@Bean(value = "dataSource")
	public ComboPooledDataSource comboPooledDataSource() throws PropertyVetoException {
		ComboPooledDataSource source = new ComboPooledDataSource();
		source.setDriverClass(jdbcDriver);
		source.setJdbcUrl(jdbcUrl);
		source.setUser(jdbcUserName);
		source.setPassword(jdbcPassWord);
		source.setAutoCommitOnClose(false);// 关闭连接后不自动提交

		return source;
	}
}
